package cn.doctorpda.conference.presenter;

import org.json.JSONException;
import org.json.JSONObject;

import cn.doctorpda.conference.bean.Msg;
import cn.doctorpda.conference.config.NetConfig;
import cn.doctorpda.conference.model.GetNameModel;
import cn.doctorpda.conference.model.IPostModel;
import cn.doctorpda.conference.okhttp.callback.StringCallback;
import cn.doctorpda.conference.utils.GsonUtil;
import cn.doctorpda.conference.utils.L;
import cn.doctorpda.conference.view.callbackview.IChangePersonalBaseView;
import okhttp3.Call;

/**
 * Created by huangjinlong on 2016/5/19.
 */
public class ChangeNamePresenter {
    private IPostModel model;
    private IChangePersonalBaseView changeNameView;

    public ChangeNamePresenter(IChangePersonalBaseView baseView) {
        model = new GetNameModel();
        changeNameView = (IChangePersonalBaseView)baseView;
    }

    public void getNewNameData(String username,String num) {
        model.postNetWorkStringData(NetConfig.GET_PERSONAL, new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {
                changeNameView.setNewError(call, e);
            }

            @Override
            public void onResponse(String response) {
                L.d("返回"+response.toString());
                try {
                    Msg msg = GsonUtil.fromJson(response, Msg.class);
                    JSONObject jsonObject = new JSONObject(response);
                    L.d("返回"+msg.getMsg().toString());
                    changeNameView.setNewView(msg);
//                    if (jsonObject.getString("encrpt_flag").equals("1")) {
//                        String data = AESUtil.decrypt(msg.getData(), AppConfig.AES_KEY);
//                        JSONObject object = new JSONObject(data);
//                        changeNameView.setNewNameView(msg);
//                    } else {
////                        L.d(msg.getData());
//
//                    }加了不调

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        }, username,num);
    }
}
